// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System.Linq;
using NUnit.Framework;
using ValidationAspects;
using ValidationAspects.Exceptions;
using ValidationAspects.Factories;

namespace TestValidationAspects
{
	[TestFixture]
	public class TestNotInRangeAttribute
	{
		[Test]
		public void Test_get_Factory()
		{
			NotInRange factory = new NotInRangeAttribute(100, 200).Factory as NotInRange;
			Assert.IsNotNull(factory);
			Assert.AreEqual(100, factory.Minimum);
			Assert.AreEqual(200, factory.Maximum);
		}

		[Test]
		public void Test_usage()
		{
			Dummy dummy = new Dummy {NotInRange = 150};

			ValidationResult result = dummy.Validate();
			Assert.IsFalse(result.IsValid);
			Assert.AreSame(typeof(ValidateNotInRangeException), ((ValidationContextException)result.ValidationException).Flatten().First().GetType());
		}

		#region Mocks
		public class Dummy
		{
			[NotInRange(100, 200)]
			public double NotInRange { get; set; }
		}
		#endregion
	}
}